// 导入路由依赖
import {useRoutes} from "react-router-dom";

// 导入所需组件，首页  关于
// import HomeView from "../views/HomeView.jsx";
// import ProductView from '../views/ProductView.jsx'
import AdminView from "../views/admin/AdminView";
import DashView from "../views/admin/DashView";
import OrderList from "../views/admin/OrderList";
// import AboutView from "../views/AboutView";
// 导入懒加载组件方法
import LazyLoad from "./LazyLoad";
import Private from "./Private";


// 创建路由
const routes = [
    {
        path: "/",
        element: LazyLoad("../views/HomeView")
    },
    {
        path: "/about",
        element: LazyLoad("../views/AboutView")
    },
    {
        path: "/product/:id",
        element: LazyLoad("../views/ProductView")
    },
    {
        path: "/Admin",
        element: (<Private><AdminView/></Private>),
        // 配置子路由
        children: [
            {
                path: "",
                element: <DashView></DashView>
            },
            {
                path: "orderlist",
                element: <OrderList></OrderList>
            }
        ]
    },
    {
        path: "*",
        element: LazyLoad("../views/NoMatch")
    }
];

// 使用useRoutes 创建
export default function RouterView() {
    // 创建路由
    const elem = useRoutes(routes);
    // 返回接口
    return elem;
}


